package page;

import java.io.File;
import java.nio.file.Paths;
import java.text.DecimalFormat;
import java.util.List;

import com.sun.corba.se.impl.naming.pcosnaming.NameServer;
import com.sun.xml.internal.bind.v2.model.core.ID;

import abstractclass.PageManagerAbstract;

public class PageManagerFile extends PageManagerAbstract {
	private String[] titles = null;
	private String[] Names  = null;
	private String[] opts   = null; 
	
	public String[] getOpts() {
		return opts;
	}

	public void setOpts(String[] opts) {
		this.opts = opts;
	}

	public String[] getTitles() {
		return titles;
	}

	public void setTitles(String[] titles) {
		this.titles = titles;
	}

	public String[] getNames() {
		return Names;
	}

	public void setNames(String[] names) {
		Names = names;
	}

	public String[] getPaths() {
		return Paths;
	}

	public void setPaths(String[] paths) {
		Paths = paths;
	}

	private String[] Paths  = null;
	private int pagecount = 10;
	
	@Override
	public List getPage(int page) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String[] getTableTitle() {
		// TODO Auto-generated method stub
		return titles;
	}

	@Override
	public String[] getDBTitles() {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public String[] getLines(int page, int line) {
		// TODO Auto-generated method stub
		if(titles==null){
			return null;
		}
		
		String[] rets = new String[titles.length];
		File file = new File(Paths[page*pagecount+line]);
		rets[0] = line+"";
		rets[1] = file.getName();
		rets[2] = file.getPath();
		DecimalFormat    df   = new DecimalFormat("######0.00");   
		double size = ((double)(file.length())/(1024.f*1024.f));
		
		rets[3] = df.format(size)+"";
		
		if(opts!=null){
			rets[4] = opts[page*pagecount+line];
		}
		
		return rets;
	}

	@Override
	public int getPageLines(int page) {
		// TODO Auto-generated method stub
		if(page*pagecount >= Names.length){
			return 0;
		}
		
		int pagetotal = Names.length - page*pagecount;
		if(pagetotal >10){
			pagetotal = 10;
		}
		
		return pagetotal;
	}

	@Override
	public int getTotalPage() {
		// TODO Auto-generated method stub
		int total = Names.length/pagecount;
		int left  = Names.length%pagecount;
		total-=1;
		if(left>0){
			total++;
		}
		return total;
	}

}
